const { role } = require('../../models/system/mrole');

class RoleService {
    static async createRole(roleData) {
        return role.create(roleData);
    }

    static async updateRole(roleId, roleData) {
        return role.findOneAndUpdate(
            { _id: roleId }, 
            { $set: roleData },
            { new: true }
        );
    }

    static async getRoleById(roleId) {
        return role.findOne({ _id: roleId }).lean();
    }

    static async getRoleList() {
        return role.find()
            .populate('roles', 'name path isMenu order parentId alias')
            .lean();
    }

    static async deleteRole(roleId) {
        return role.findOneAndDelete({ _id: roleId });
    }
}

module.exports = RoleService;
